import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.util.Arrays;

public class strValidation {
	
	//this function returns true iff all chars in str are ASCII
	public static boolean  testAscii(String str) {

	// This string contains a non ASCII character which will produce exception
	// in this program. While the second string has a valid ASCII only chars.

	byte[] invalidBytes = str.getBytes();
	byte[] validBytes = str.getBytes();

	// Returns a charset object for the named charset.

	CharsetDecoder decoder = Charset.forName("US-ASCII").newDecoder();

	try {

		CharBuffer buffer = decoder.decode(ByteBuffer.wrap(validBytes));


		buffer = decoder.decode(ByteBuffer.wrap(invalidBytes));
		return true;

		}
	catch (CharacterCodingException e) 
		{
		return false;

		}

	}
	
	//if a disc has several Disc ID's, we take the first one.
	public static String verifyDiscID(String str){
		if (str.contains(",")){
			String[] result=str.split(",");
			return result[0];			
		}
		else return str;
		
	}

}
